#########################################################################
# Utilities.R
# Aim: to collect functions for replication
#########################################################################


#########################################################################
# For Figure 4
#########################################################################

get_obs_rank <- function(order, i_first, i_second, i_third, i_fourth, df){
  
  order <- obs[order] 
  first <- obs[i_first] %>% pull() 
  second <- obs[i_second] %>% pull() 
  third <- obs[i_third] %>% pull() 
  fourth <- obs[i_fourth] %>% pull() 

  obs_rank <- case_when(order=="1234" ~ paste0(first,second,third,fourth),
                        order=="1243" ~ paste0(first,second,fourth,third),
                        order=="1324" ~ paste0(first,third,second,fourth),
                        order=="1342" ~ paste0(first,third,fourth,second),
                        order=="1423" ~ paste0(first,fourth,second,third),
                        order=="1432" ~ paste0(first,fourth,third,second),
                        order=="2134" ~ paste0(second,first,third,fourth),
                        order=="2143" ~ paste0(second,first,fourth,third),
                        order=="2314" ~ paste0(second,third,first,fourth),
                        order=="2341" ~ paste0(second,third,fourth,first),
                        order=="2413" ~ paste0(second,fourth,first,third),
                        order=="2431" ~ paste0(second,fourth,third,first),
                        order=="3124" ~ paste0(third,first,second,fourth),
                        order=="3142" ~ paste0(third,first,fourth,second),
                        order=="3214" ~ paste0(third,second,first,fourth),
                        order=="3241" ~ paste0(third,second,fourth,first),
                        order=="3412" ~ paste0(third,fourth,first,second),
                        order=="3421" ~ paste0(third,fourth,second,first),
                        order=="4123" ~ paste0(fourth,first,second,third),
                        order=="4132" ~ paste0(fourth,first,third,second),
                        order=="4213" ~ paste0(fourth,second,first,third),
                        order=="4231" ~ paste0(fourth,second,third,first),
                        order=="4312" ~ paste0(fourth,third,first,second),
                        order=="4321" ~ paste0(fourth,third,second,first))

return(obs_rank)
    
}


#############################################################################
# END OF THIS R SOURCE FILE
#############################################################################
